#include "chatitem.h"
#include "ui_chatitem.h"

ChatItem::ChatItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ChatItem)
{
    ui->setupUi(this);
}

ChatItem::~ChatItem()
{
    delete ui;
}

void ChatItem::setItemData(QString username, QDateTime timestamp, QString latestMessage)
{
    setName(username);
    setTimestamp(timestamp);
    setLatestMessage(latestMessage);
}

void ChatItem::setItem(Message message)
{

}

void ChatItem::setName(QString name)
{
    ui->label_username->setText(name);
}

void ChatItem::setTimestamp(QDateTime timestamp)
{
    ui->label_timpstamp->setText(timestamp.toString("yy/M/d h:m"));
}

void ChatItem::setLatestMessage(QString latestMessage)
{
    ui->label_latestMessage->setText(latestMessage);
}

void ChatItem::mousePressEvent(QMouseEvent *event)
{
    m_chatWidget->show();
    return QWidget::mousePressEvent(event);
}

void ChatItem::setChatWidget(ChatWidget *newChatWidget)
{
    m_chatWidget = newChatWidget;
}

ChatWidget *ChatItem::chatWidget() const
{
    return m_chatWidget;
}
